package com.lanou.list;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zyj
 * @date 2022年05月19日 15:04
 */
public class 集合转数组 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("张无忌");
        //集合转数组 建议使用<T> T[] toArray(T[] a)
        String[] strings = {};
        String[] strings1 = list.toArray(strings);
        for (String s:strings1) {
            System.out.println(s);
        }

        System.out.println("***********************");
        String[] strings2 = list.toArray(new String[list.size()]);
        for (String s:strings2) {
            System.out.println(s);
        }
        System.out.println("***********************");
        String[] strings3 = new String[list.size()];
        list.toArray(strings3);
        for (String s:strings3) {
            System.out.println(s);
        }


        //数组转集合
        List<String> list1 = Arrays.asList(strings3);
        List<String> list2 = new ArrayList<>(list1);
       // list1.add("");
//        list1.remove("张三");
        list1.set(3,"黄圣诞");
        System.out.println(list1.get(0));
        System.out.println("*****************");

        for (String s:list1) {
            System.out.print(s + "\t");
        }
    }
}
